<?php

namespace Home\Controller;

use Home\Logic\Ajax\AbstractAjax;

class AjaxController extends CommonController
{
    public function view()
    {
        if (IS_AJAX) {
            $act = I('request.act', '', 'trim');
            $act = substr($act, 5);  // 去除ajax_前缀
            $className = '\\Home\\Model\\Ajax\\' . parse_name($act, 1);
            if (class_exists($className)) {
                $ajax = new $className;
                $this->ajaxReturn($ajax->handle());
            } else {
                $ajax['status'] = 0;
                $ajax['content'] = $act . "不允许请求";
                $this->ajaxReturn($ajax);
            }
        } else {
            $ajax['status'] = 0;
            $ajax['content'] = "参数非法";
            $this->ajaxReturn($ajax);
        }
    }
}